#include "ExtractBorderModel.h"

#include "core/AppDirectory.h"

namespace {
const QString UserFilename = "pcl.extract_border_model.json";
}

ExtractBorderModel::ExtractBorderModel()
    : BasePclModel()
{
    setPclHelpPage("https://pcl.readthedocs.io/projects/tutorials/en/master/range_image_border_extraction.html");
}

ExtractBorderModel& ExtractBorderModel::get()
{
    static ExtractBorderModel instance;
    if (instance.filename().isEmpty()) {
        instance.setFilename(AppDirectory::get().getAppDocFile(UserFilename));
        instance.load();
    }
    return instance;
}

void ExtractBorderModel::fromJson(const QJsonObject& json, QStringList& errorList)
{
    BasePclModel::fromJson(json, errorList);

    pcdFile_ = json["pcdFile"].toString(pcdFile_);
    radiusSearch_ = json["radiusSearch"].toDouble(radiusSearch_);
}

QJsonObject ExtractBorderModel::toJson() const
{
    QJsonObject json = BasePclModel::toJson();

    json.insert("pcdFile", QJsonValue(pcdFile_));
    json.insert("radiusSearch", QJsonValue(radiusSearch_));

    return json;
}
